Life is fragile and under constant attack. Over millions of years, Nature has developed a series of systems to increase its resilience, pain being one of the most critical. Although always unpleasant, pain is what directs our attention to injuries, preventing long-term handicaps and even death. Without it we would happily burn our hands in boiling water, or walk around with a broken leg. Pain, then, is a fundamental part of life.1Congenital analgesia is a condition in which a person cannot feel pain. Understanding how these people live their daily lives, may help you develop an appreciation for how important pain is.
The International Association for the Study of Pain (IASP)2 the IASP website has a useful dictionary of terms related to pain is the leading group tasked with studying pain, and creating guidelines for its treatment. It defines pains as:
An unpleasant sensory and emotional experience associated with actual or potential tissue damage, or described in terms of such damage.
We can break this down in two parts: first, pain is both a sensory and emotional experience. This means it is subjective, different from individual to individual, and dependent on more than biology (the actual pain receptors). Emotions are not a mere consequence of pain, but an important component of the whole system. They are also a common source for misinterpretation and under- and over-treatment3 the so called sudlandersyndrom in Germany — someone that typically exteriorizes her or his emotions, can have more exuberant reactions to pain, in comparison to a more timid person. This should not be outright discarded, but in fact function as a guide for the physician to modulate treatment. A little extra assurance, a smile and a touch on the shoulder can go a long way in calming down a patient, and begin an effective pain therapy without a single prescription drug. Positive emotions and the knowledge that one is being taken of are are extremely effective in modulation pain (Flaten 2014Flaten, Magne Arve. 2014. “Pain-related negative emotions and placebo analgesia.” Handbook of Experimental Pharmacology 225:81–96. https://doi.org/10.1007/978-3-662-44519-8_5.).
The second part of defines pain in terms of actual or perceived damage. This is important because even in cases without any (current) biological cause, the experience of pain is still quite real. A physician should take all accounts of pain seriously, not just when the patient clearly broke a foot or ate bad food. A good example of this is fibromyalgia, which as of now has no known biological cause, but can have a massive impact on a person’s quality of life (Clauw 2014Clauw, Daniel J. 2014. “Fibromyalgia: A clinical review.” https://doi.org/10.1001/jama.2014.3266.).
The IASP definition, while important for a standardized approach to pain, does not take time into account.
Acute
Chronic
Duration
short
recurrent
Cause
known and treatable
unknown, unspecific, or known but not treatable
Function
warning
no physiological function
Intervention
analgesy
deconstruction of
Therapeutic objective
no pain
pain management, better control
Psychological consequences
hope the therapy will work
resignation, helplessness
Define chronic pain
The latest guidelines define chronic as “pain that persists or recurs for longer than 3 months.”4 you can explore more at the ICD-11 website These patients have commonly been to multiple doctors, tried various therapies without success and, most importantly, feel the pain has a substantial negative impact on their daily lives. It is thus also usual for these patients to present negative psychological symptoms, such as depression, and feelings of helplessness and uselessness. All of this can create a “snowball effect”, with the patient avoiding more and more activities, and becoming more and more isolated and focused on her or his negative thoughts.
It is critical to understand that this is not a rare situation. As of 2006, the prevalence of chronic pain in Europe was around 20% (Breivik et al. 2006Breivik, Harald, Beverly Collett, Vittorio Ventafridda, Rob Cohen, and Derek Gallacher. 2006. “Survey of chronic pain in Europe: Prevalence, impact on daily life, and treatment.” European Journal of Pain 10 (4):287–333. https://doi.org/10.1016/j.ejpain.2005.06.009.), with similarly high figures for the rest of world (Elzahaf et al. 2012Elzahaf, Raga A., Osama A. Tashani, Biddy A. Unsworth, and Mark I. Johnson. 2012. “The prevalence of chronic pain with an analysis of countries with a Human Development Index less than 0.9: a systematic review without meta-analysis.” Current Medical Research and Opinion 28 (7):1221–9. https://doi.org/10.1185/03007995.2012.703132.). Even more importantly, data from 20165 Global Burden of Disease Study 2016 (GBD 2016) shows low back and neck pain is the number one cause of disability in Germany, meaning the likelihood of meeting one such patient is high.
Pain pathways
We can boil the somatosensory system down to five critical components: a nociceptor (generates the signal), a peripheral neve (conducts the signal to the spinal cord), the spinal cord (activates reflexes, modulates pain and further sends information to the thalamus), the thalamus (integration of sensory discriminative, affective motivational and cognitive-evaluative components) and finally the somatosensory cortex (stimulus localization).
There are multiple types of nociceptors:
Fasern
Charakteristika
Geschwindigkeit
Aα/Aβ
myelinisiert
40–80 m/s (schnell)
großer Durchmesser
nicht nozizeptiv
leichte Berührung
Aδ I/II
leicht myelinisiert
2,5–36 m/s (schnell)
mittlerer Durchmesser
nozizeptiv
C
nicht myelinisiert
0,5–1,7 m/s (langsam)
kleiner Durchmesser
nozizeptiv
polymodal
There are different types of pain, depending on its (suspected) origin.
Psychogenic pain: based on psychological conflicts, without any organic cause. A common example is a child with a strong belly ache, after the parents had a big fight. This pain is still real, in the sense that the patient does indeed suffer and is in distress. A doctor should still make a thorough diagnostic, to make sure an organic cause is not present.
Neuropathic pain: has its origin in damage or diseases of the somatosensory nervous system. Common in diabetes patients, multiple sclerosis and after a stroke. Phantom pain syndrom is a special case of this type of pain. Patients may report pain from otherwise non-painful stimuli (allodynia, e.g. a kiss on the cheek), describing it as an electric shock, a needle sting or a burning sensation that travels along the path of the nerve. Up to 7% to 8% of the European population is affected, and in 5% of persons it may be severe (???).
Nociceptive pain: the most common type. This is pain that emerges from activation of a nociceptor, i.e. pain receptor. We have all experienced this after trying to impress someone with our balance skills, only to fail miserably. Exposure to extreme heat or cold will also activate these receptors. Sensory nerve fibres stimulated beyond harmful intensity send a signal to the spinal cord, and then to the brain, which we feel as pain.
Myofascial pain syndrome: after using a muscle repetitively, or very stressfull situation, it is possible to have some muscle pain or soreness. This can be felt as pressure on sensitive points in your muscles (trigger points), sometimes even in unrelated parts of your body. In some people, this pain can linger and become worse, at which point we talk about a myofascial pain syndrome. Fibromyalgia is thought to evolve from this syndrome.
The Tufte handout style is a style that Edward Tufte uses in his books and handouts. Tufte’s style is known for its extensive use of sidenotes, tight integration of graphics with text, and well-set typography. This style has been implemented in LaTeX and HTML/CSS6 See Github repositories tufte-latex and tufte-css, respectively. We have ported both implementations into the tufte package. If you want LaTeX/PDF output, you may use the tufte_handout format for handouts, and tufte_book for books. For HTML output, use tufte_html. These formats can be either specified in the YAML metadata at the beginning of an R Markdown document (see an example below), or passed to the rmarkdown::render() function. See (???) more information about rmarkdown.
---
title: "An Example Using the Tufte Style"
author: "John Smith"
output:
tufte::tufte_handout: default
tufte::tufte_html: default
---
There are two goals of this package:
To produce both PDF and HTML output with similar styles from the same R Markdown document;
To provide simple syntax to write elements of the Tufte style such as side notes and margin figures, e.g. when you want a margin figure, all you need to do is the chunk option fig.margin = TRUE, and we will take care of the details for you, so you never need to think about \begin{marginfigure} \end{marginfigure} or <span class="marginfigure"> </span>; the LaTeX and HTML code under the hood may be complicated, but you never need to learn or write such code.
This style provides first and second-level headings (that is, # and ##), demonstrated in the next section. You may get unexpected output if you try to use ### and smaller headings.
In his later books7Beautiful Evidence, Tufte starts each section with a bit of vertical space, a non-indented paragraph, and sets the first few words of the sentence in small caps. To accomplish this using this style, call the newthought() function in tufte in an inline R expression`r ` as demonstrated at the beginning of this paragraph.8 Note you should not assume tufte has been attached to your R session. You should either library(tufte) in your R Markdown document before you call newthought(), or use tufte::newthought().
Figures
Margin Figures
Images and graphics play an integral role in Tufte’s work. To place figures in the margin you can use the knitr chunk option fig.margin = TRUE. For example:
Note the use of the fig.cap chunk option to provide a figure caption. You can adjust the proportions of figures using the fig.width and fig.height chunk options. These are specified in inches, and will be automatically scaled down to fit within the handout margin.
Arbitrary Margin Content
In fact, you can include anything in the margin using the knitr engine named marginfigure. Unlike R code chunks ```{r}, you write a chunk starting with ```{marginfigure} instead, then put the content in the chunk. See an example on the right about the first fundamental theorem of calculus.
We know from the first fundamental theorem of calculus that for \(x\) in \([a, b]\): \[\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x).\]
For the sake of portability between LaTeX and HTML, you should keep the margin content as simple as possible (syntax-wise) in the marginefigure blocks. You may use simple Markdown syntax like **bold** and _italic_ text, but please refrain from using footnotes, citations, or block-level elements (e.g. blockquotes and lists) there.
Note: if you set echo = FALSE in your global chunk options, you will have to add echo = TRUE to the chunk to display a margin figure, for example ```{marginfigure, echo = TRUE}.
Full Width Figures
You can arrange for figures to span across the entire page by using the chunk option fig.fullwidth = TRUE.
Other chunk options related to figures can still be used, such as fig.width, fig.cap, out.width, and so on. For full width figures, usually fig.width is large and fig.height is small. In the above example, the plot size is \(10 \times 2\).
Main Column Figures
Besides margin and full width figures, you can of course also include figures constrained to the main column. This is the default type of figures in the LaTeX/HTML output.
One of the most prominent and distinctive features of this style is the extensive use of sidenotes. There is a wide margin to provide ample room for sidenotes and small figures. Any use of a footnote will automatically be converted to a sidenote.9 This is a sidenote that was entered using a footnote.
If you’d like to place ancillary information in the margin without the sidenote mark (the superscript number), you can use the margin_note() function from tufte in an inline R expression. This is a margin note. Notice that there is no number preceding the note. This function does not process the text with Pandoc, so Markdown syntax will not work here. If you need to write anything in Markdown syntax, please use the marginfigure block described previously.
References
References can be displayed as margin notes for HTML output. For example, we can cite R here (???). To enable this feature, you must set link-citations: yes in the YAML metadata, and the version of pandoc-citeproc should be at least 0.7.2. You can always install your own version of Pandoc from http://pandoc.org/installing.html if the version is not sufficient. To check the version of pandoc-citeproc in your system, you may run this in R:
system2('pandoc-citeproc', '--version')
If your version of pandoc-citeproc is too low, or you did not set link-citations: yes in YAML, references in the HTML output will be placed at the end of the output document.
Tables
You can use the kable() function from the knitr package to format tables that integrate well with the rest of the Tufte handout style. The table captions are placed in the margin like figures in the HTML output.
knitr::kable(
mtcars[1:6, 1:6], caption = 'A subset of mtcars.'
)
A subset of mtcars.
mpg
cyl
disp
hp
drat
wt
Mazda RX4
21.0
6
160
110
3.90
2.620
Mazda RX4 Wag
21.0
6
160
110
3.90
2.875
Datsun 710
22.8
4
108
93
3.85
2.320
Hornet 4 Drive
21.4
6
258
110
3.08
3.215
Hornet Sportabout
18.7
8
360
175
3.15
3.440
Valiant
18.1
6
225
105
2.76
3.460
Block Quotes
We know from the Markdown syntax that paragraphs that start with > are converted to block quotes. If you want to add a right-aligned footer for the quote, you may use the function quote_footer() from tufte in an inline R expression. Here is an example:
“If it weren’t for my lawyer, I’d still be in prison. It went a lot faster with two people digging.”
Without using quote_footer(), it looks like this (the second line is just a normal paragraph):
“Great people talk about ideas, average people talk about things, and small people talk about wine.”
— Fran Lebowitz
Responsiveness
The HTML page is responsive in the sense that when the page width is smaller than 760px, sidenotes and margin notes will be hidden by default. For sidenotes, you can click their numbers (the superscripts) to toggle their visibility. For margin notes, you may click the circled plus signs to toggle visibility.
More Examples
The rest of this document consists of a few test cases to make sure everything still works well in slightly more complicated scenarios. First we generate two plots in one figure environment with the chunk option fig.show = 'hold':
p <- ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point()
p
p + geom_smooth()
Two plots in one figure environment.
Then two plots in separate figure environments (the code is identical to the previous code chunk, but the chunk option is the default fig.show = 'asis' now):
p <- ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point()
p
Two plots in separate figure environments (the first plot).
p + geom_smooth()
Two plots in separate figure environments (the second plot).
You may have noticed that the two figures have different captions, and that is because we used a character vector of length 2 for the chunk option fig.cap (something like fig.cap = c('first plot', 'second plot')).
Next we show multiple plots in margin figures. Similarly, two plots in the same figure environment in the margin:
Two plots in one figure environment in the margin.
p
p + geom_smooth(method = 'lm')
Then two plots from the same code chunk placed in different figure environments:
knitr::kable(head(iris, 15))
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Species
5.1
3.5
1.4
0.2
setosa
4.9
3.0
1.4
0.2
setosa
4.7
3.2
1.3
0.2
setosa
4.6
3.1
1.5
0.2
setosa
5.0
3.6
1.4
0.2
setosa
5.4
3.9
1.7
0.4
setosa
4.6
3.4
1.4
0.3
setosa
5.0
3.4
1.5
0.2
setosa
4.4
2.9
1.4
0.2
setosa
4.9
3.1
1.5
0.1
setosa
5.4
3.7
1.5
0.2
setosa
4.8
3.4
1.6
0.2
setosa
4.8
3.0
1.4
0.1
setosa
4.3
3.0
1.1
0.1
setosa
5.8
4.0
1.2
0.2
setosa
Two plots in separate figure environments in the margin (the first plot).
p
knitr::kable(head(iris, 12))
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Species
5.1
3.5
1.4
0.2
setosa
4.9
3.0
1.4
0.2
setosa
4.7
3.2
1.3
0.2
setosa
4.6
3.1
1.5
0.2
setosa
5.0
3.6
1.4
0.2
setosa
5.4
3.9
1.7
0.4
setosa
4.6
3.4
1.4
0.3
setosa
5.0
3.4
1.5
0.2
setosa
4.4
2.9
1.4
0.2
setosa
4.9
3.1
1.5
0.1
setosa
5.4
3.7
1.5
0.2
setosa
4.8
3.4
1.6
0.2
setosa
Two plots in separate figure environments in the margin (the second plot).
p + geom_smooth(method = 'lm')
knitr::kable(head(iris, 5))
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Species
5.1
3.5
1.4
0.2
setosa
4.9
3.0
1.4
0.2
setosa
4.7
3.2
1.3
0.2
setosa
4.6
3.1
1.5
0.2
setosa
5.0
3.6
1.4
0.2
setosa
We blended some tables in the above code chunk only as placeholders to make sure there is enough vertical space among the margin figures, otherwise they will be stacked tightly together. For a practical document, you should not insert too many margin figures consecutively and make the margin crowded.
You do not have to assign captions to figures. We show three figures with no captions below in the margin, in the main column, and in full width, respectively.
# a boxplot of weight vs transmission; this figure
# will be placed in the margin
ggplot(mtcars2, aes(am, wt)) + geom_boxplot() +
coord_flip()
# a figure in the main column
p <- ggplot(mtcars, aes(wt, hp)) + geom_point()
p
# a fullwidth figure
p + geom_smooth(method = 'lm') + facet_grid(~ gear)
Some Notes on Tufte CSS
There are a few other things in Tufte CSS that we have not mentioned so far. If you prefer sans-serif fonts, use the function sans_serif() in tufte. For epigraphs, you may use a pair of underscores to make the paragraph italic in a block quote, e.g.
I can win an argument on any topic, against any opponent. People know this, and steer clear of me at parties. Often, as a sign of their great respect, they don’t even invite me.
We hope you will enjoy the simplicity of R Markdown and this R package, and we sincerely thank the authors of the Tufte-CSS and Tufte-LaTeX projects for developing the beautiful CSS and LaTeX classes. Our tufte package would not have been possible without their heavy lifting.
You can turn on/off some features of the Tufte style in HTML output. The default features enabled are:
If you do not want the page background to be lightyellow, you can remove background from tufte_features. You can also customize the style of the HTML page via a CSS file. For example, if you do not want the subtitle to be italic, you can define
h3.subtitle em {
font-style: normal;
}
in, say, a CSS file my_style.css (under the same directory of your Rmd document), and apply it to your HTML output via the css option, e.g.,
There is also a variant of the Tufte style in HTML/CSS named “Envisoned CSS”. This style can be used by specifying the argument tufte_variant = 'envisioned' in tufte_html()10 The actual Envisioned CSS was not used in the tufte package. We only changed the fonts, background color, and text color based on the default Tufte style., e.g.
To see the R Markdown source of this example document, you may follow this link to Github, use the wizard in RStudio IDE (File -> New File -> R Markdown -> From Template), or open the Rmd file in the package: